package cn.edu.nuc.onlinestore.util;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.List;

import cn.edu.nuc.onlinestore.vo.Goods;

public class UserBuyutil {
	public List<Goods> getList(){
		
		try {
			Socket client=new Socket("127.0.0.1",8080);
			
			DataOutputStream din=new DataOutputStream(client.getOutputStream());
			din.writeUTF("get@get");
			
			ObjectInputStream obj=new ObjectInputStream(client.getInputStream());
			List<Goods> list=(List)obj.readObject();
			System.out.println(list.get(0));
			
			din.close();
			obj.close();
			client.close();
			
			return list;
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return null;
		
	}

	public boolean Send(String name) {
		try {
			Socket client=new Socket("127.0.0.1",8080);
			
			DataOutputStream din=new DataOutputStream(client.getOutputStream());
			din.writeUTF("del@"+name);
			
			DataInputStream obj=new DataInputStream(client.getInputStream());
			boolean t5=obj.readBoolean();
			System.out.println(t5);
			
			din.close();
			obj.close();
			client.close();
			
			return t5;
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return false;
		// TODO Auto-generated method stub
		
	}
}
